<?php

/**
 * CodeRS - Atviras kodas Lietuvai
 * Copyright (C) 2007 CodeRS www.coders.lt info@coders.lt
 * MightMedia TVS
 * shoutbox.php - rėksnių dėžutė.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * 
 * Ši programa yra laisva. Jūs galite ją platinti ir/arba modifikuoti
 * remdamiesi Free Software Foundation paskelbtomis GNU Bendrosios
 * Viešosios licencijos sąlygomis: 2 licencijos versija, arba (savo
 * nuožiūra) bet kuria vėlesne versija.
 * 
 * Ši programa platinama su viltimi, kad ji bus naudinga, bet BE JOKIOS
 * GARANTIJOS; be jokios numanomos PERKAMUMO ar TINKAMUMO KONKRETIEMS
 * TIKSLAMS garantijos. Žiūrėkite GNU Bendrąją Viešąją licenciją norėdami
 * sužinoti smulkmenas.
 * 
 * Jūs turėjote kartu su šia programa gauti ir GNU Bendrosios Viešosios
 * licencijos kopija; jei ne - rašykite Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**/

if ($_SERVER['PHP_SELF'] == __FILE__) { header('location: ?'); exit(); }

if (isset($url['p']) && isnum($url['p']) && $url['p'] > 0) $p = (int) $url['p']; else $p = 0; //Puslapis
$limit = $conf['Chat_limit'];
$viso = $db->kiek_irasu(T_SAUKYKLA);//$viso = kiek(T_SAUKYKLA);

// MODERAVIMAS - start
if (MOD == 1) {
	// DELETE
	if (isset($url['d']) && !empty($url['d']) && isnum($url['d'])) {
		if ($db->uzklausa("DELETE FROM `".T_SAUKYKLA."` WHERE `id`='".(int) $url['d']."' LIMIT 1"))
			msg("Administravimas","Žinutė: $id ištrinta","informacija");
		else
			klaida("Klaida","Žinutė nebuvo pakeista");
		perkelti("?id,49;p,$p", "letai");
	}
	// EDIT
	if (isset($url['r']) && !empty($url['r']) && isnum($url['r'])) {
		if(!isset($_POST['chat_box']) || $_POST['chat_box'] != 'Redaguoti' || empty($_POST['msg'])) {
			$inf = $db->masyvas($db->uzklausa("SELECT `msg` FROM `".T_SAUKYKLA."` WHERE `id`=".(int) $url['r']." LIMIT 1"));
			lentele("Žinutės redagavimas", '<form action="" method="post">
					<textarea name="msg" rows="3" cols="25" wrap="on" style="width:265px">'.input($inf['msg']).'</textarea><br />
					<input type="submit" name="chat_box" value="Redaguoti" />
					</form>');
			unset($inf);
		} else {
			$msg = $db->fix($_POST['msg'])."\n[sm][i]Redagavo: ".$db->fix($ses->user_data['username'])."[/i][/sm]";
			if ($db->uzklausa("UPDATE `".T_SAUKYKLA."` SET `msg`='".$db->fix($msg)."' WHERE `id` =".(int) $url['r']." LIMIT 1"))
				msg("Sėkmė", "Žinutė sėkmingai pakeista");
			else
				klaida("Klaida", "Žinutė nebuvo pakeista");
			perkelti("?id,49;p,$p", "letai");
		}
	}
}
// MODERAVIMAS - end


echo "<br /><div style=\"border:1px solid pink; padding:2px; background-color: white;\"><div style=\"background-color: #eaf4f9; background-image: url(templates/default/images/block_vidus_fonas.gif);background-repeat: repeat-x; padding-left: 10px; padding-right: 10px; padding-bottom: 10px; height:100%; border: 2px solid #addbf1;\">
<div style=\"border-bottom: 1px solid #659aba; text-align:center; font-size:13px; font-weight: bold; margin-bottom:5px;\">Šaukyklos archyvas</div>";

// ŠAUKYKLOS PRANEŠIMAI - start
$sql2 = $db->uzklausa("SELECT SQL_CACHE * FROM `".T_SAUKYKLA."` ORDER BY `time` DESC LIMIT $p, $limit");
if ($viso > $limit) echo puslapiai($p,$limit,$viso,10)."<div style=\"padding-bottom: 5px;\"></div>";
while ($row = mysql_fetch_assoc($sql2)) {
	
	if (PRISIJUNGES && $row['nikas'] != $ses->user_data['username']) $extra = "<a href=\"?id,45;n,1;u,".$row['nikas']."\"><img src=\"images/pm/mail.png\" alt=\"pm\" border=\"0\" /></a> ";
	else $extra = "";

	if (ADMIN) { $extra .= "<a href=\"".url("d,".$row['id'])."\" onclick=\"return confirm('Ar tikrai norite trinti?')\"><img src='images/icons/page_white_delete.png' alt='[d]' title='trinti' class='middle' border='0' /></a> <a href='".url("r,".$row['id']."")."'><img src='images/icons/page_white_edit.png' alt='[r]' title='redaguoti' class='middle' border='0' /></a> <a href='?id,49;b,".$row['niko_id']."' onclick=\"return confirm('Ar tikrai norite blokuoti?')\"><img src='images/icons/user_delete.png' alt='[b]' title='baninti' class='middle' border='0' /></a> "; }

	inline_box(
		"<a href=\"?id,49;p,$p#".$row['id']."\" name=\"".$row['id']."\" id=\"".$row['id']."\"><img src=\"images/icons/bullet_black.png\" alt=\"#\" class=\"middle\" border=\"0\" /></a> <a href=\"?id,47;m,".$row['niko_id']."\" title=\"Apie ".$row['nikas']."\">".$row['nikas']."</a> (".$row['time'].") - ".kada($row['time'])." $extra",
		smile(bbchat($row['msg']))
	);

}
if ($viso > $limit) echo puslapiai($p,$limit,$viso,10);
//ŠAUKYKLOS PRANEŠIMAI - end

echo "</div></div><br />";
?>
